package com.it.springboot_day01demo.controller;

import com.it.springboot_day01demo.bean.Emp;
import com.it.springboot_day01demo.service.EmpService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@RestController//@RestController约等于@Controller+@Responsebody:返回JSON类型的字段
public class EmpController {
    @Resource
    private EmpService empService;
    @RequestMapping(value="selectAllEmpList.do",produces="application/json; charset=utf-8")
    public List<Emp> selectAllEmpList(){

        return empService.selectAllEmpList();
    }

    @RequestMapping("/updateEmpById.do")
    public String updateEmpById(){
        Emp emp = new Emp();
        emp.setEmpno(6);
        emp.setEname("乌西迪西");
        int result = empService.updateEmpById(emp);
        if(result>0){
            return "success!";
        }else{
            return "fall";
        }
    }

    @RequestMapping("addEmp.do")
    public String addEmp(){
        Emp emp = new Emp();
        //emp.setEmpno(10);
        emp.setEname("恍恍惚惚");
        emp.setSalary(6);
        DateFormat date = new SimpleDateFormat("yyyy-MM-dd");
        String D = date.format(new Date());
        System.out.println(D);
        emp.setHiredate(D);
        int result = empService.addEmpBy(emp);
        if(result>0){
            return "success!";
        }else{
            return "fall";
        }
    }
}
